package com.dxy.elasticsearch.config;

import lombok.Getter;
import lombok.Setter;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.concurrent.TimeUnit;

/**
 * @author wudapei
 * @date 2022-11-21 14:00
 */
@Setter
@Getter
@ConfigurationProperties(prefix = "es")
public class EsProperties {
    private String nodes;
    private String username;
    private String password;
    private int connectTimeoutMs = 60000;
    private int socketTimeoutMs = 60000;
    private int connectionRequestTimeoutMs = 10000;
    private int maxConnTotal = 200;
    private int maxConnPerRoute = 50;
    private int keepAliveMs = 30000;
    private EsProperties.Search search = new EsProperties.Search();
    private Integer retryCountOnConflict = 3;
    private RefreshPolicy defaultRefreshPolicy;
    private Integer defaultMaxInsertSize;

    public EsProperties() {
        this.defaultRefreshPolicy = RefreshPolicy.NONE;
        this.defaultMaxInsertSize = 5000;
    }

    @Setter
    @Getter
    public static class Search {
        private long scrollKeepAliveMs;
        private int defaultSearchMaxSize;
        private int defaultScrollMaxSize;
        private int maxTermsQuerySize;

        public Search() {
            this.scrollKeepAliveMs = TimeUnit.MINUTES.toMillis(100L);
            this.defaultSearchMaxSize = 10000;
            this.defaultScrollMaxSize = 5000;
            this.maxTermsQuerySize = -1;
        }
    }
}
